﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Cfg;
using System.Reflection;

namespace NHibernateTest
{
  class Program
  {
    static ISessionFactory SessionFactory;

    static ISession OpenSession()
    {
      if (SessionFactory == null) // not threadsafe
      { 
        // SessionFactories are expensive, create only once
        Configuration conf = new Configuration();     
        conf.AddAssembly(Assembly.GetCallingAssembly());
        SessionFactory = conf.BuildSessionFactory();        
      }

      return SessionFactory.OpenSession();
    }

    static void Main(string[] args)
    { 
      ISession session = OpenSession();
      IQuery query = session.CreateQuery("FROM ApplicationInterface");
      IList<ApplicationInterface> appInterfaces = query.List<ApplicationInterface>();
      Console.WriteLine("appInterfaces.Count = " + appInterfaces.Count);
      Console.ReadKey();
    }
  }
}
